﻿using System;

using Top.Api;
using DreamCube.Foundation.Basic.Utility;

namespace DreamCube.TaobaoGJ.BLL
{
    public static class TB_AppKeyFunc
    {
        //public static string GetCodeUrl = ("https://oauth.taobao.com/authorize?client_id=" + appkey + "&response_type=code&redirect_uri=" + CallBackUrl + "");
        //public static string GetTokenUrl = "https://oauth.taobao.com/token/";
        //public static string sessionkeyurl = ("http://container.open.taobao.com/container?appkey=" + appkey + "");
        
        /// <summary>
        /// 获取一个淘宝调用的TopClient对象
        /// </summary>
        /// <returns></returns>
        public static DefaultTopClient GetTopClient()
        {
            return new DefaultTopClient(CallUrl, AppKey, AppSecret);
        }

        /// <summary>
        /// 调用的Url
        /// </summary>
        public static String CallUrl
        {
            get { return Properties.Resources.TB_CallUrl; }
        }

        /// <summary>
        /// 回调的Url
        /// </summary>
        public static String CallBackUrl
        {
            get { return Properties.Resources.TB_CallBackUrl; }
        }

        /// <summary>
        /// 获取授权的Url
        /// </summary>
        public static String GetSessionUrl
        {
            get { return Properties.Resources.TB_GetSessionUrl; }
        }

        private static String appKey;
        /// <summary>
        /// AppKey值
        /// </summary>
        public static String AppKey
        {
            get
            {
                //return Properties.Resources.TB_AppKey;
                if (!String.IsNullOrEmpty(appKey)) return appKey;
                Boolean needDecrypt = false;
                if (Boolean.TryParse(MyConfig.GetAppSettingValue("needDecrypt"), out needDecrypt) && needDecrypt)
                    appKey = MySecurity.Decrypt(MyConfig.GetAppSettingValue("TB_AppKey"));
                else
                    appKey = MyConfig.GetAppSettingValue("TB_AppKey");
                return appKey;
            }
        }

        private static String appSecret;
        /// <summary>
        /// TB_AppSecret
        /// </summary>
        public static String AppSecret
        {
            get
            {
                //return Properties.Resources.TB_AppSecret;
                if (!String.IsNullOrEmpty(appSecret)) return appSecret;
                Boolean needDecrypt = false;
                if (Boolean.TryParse(MyConfig.GetAppSettingValue("needDecrypt"), out needDecrypt) && needDecrypt)
                    appSecret = MySecurity.Decrypt(MyConfig.GetAppSettingValue("TB_AppSecret"));
                else
                    appSecret = MyConfig.GetAppSettingValue("TB_AppSecret");
                return appSecret;
            }
        }
    }
}
